import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import java.awt.GridLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.JRadioButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;


public class hw01 extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField msg;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			hw01 dialog = new hw01();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public hw01() {
		setBounds(100, 100, 303, 337);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new BorderLayout(0, 0));
		{
			JPanel panel = new JPanel();
			contentPanel.add(panel, BorderLayout.CENTER);
			GridBagLayout gbl_panel = new GridBagLayout();
			gbl_panel.columnWeights = new double[]{0.0, 0.0, 0.0};
			gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0};
			panel.setLayout(gbl_panel);
			{
				JButton btn1 = new JButton("1");
				btn1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						JButton j = (JButton) e.getSource();
						if(msg.getText().equals("0")){
							msg.setText(j.getText());
						}else
							msg.setText(msg.getText()+j.getText());
					}
				});
				GridBagConstraints gbc_btn1 = new GridBagConstraints();
				gbc_btn1.fill = GridBagConstraints.BOTH;
				gbc_btn1.insets = new Insets(0, 0, 5, 5);
				gbc_btn1.gridx = 0;
				gbc_btn1.gridy = 0;
				panel.add(btn1, gbc_btn1);
			}
			{
				JButton btn2 = new JButton("2");
				btn2.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						JButton j = (JButton) e.getSource();
						if(msg.getText().equals("0")){
							msg.setText(j.getText());
						}else
							msg.setText(msg.getText()+j.getText());
					}
				});
				GridBagConstraints gbc_btn2 = new GridBagConstraints();
				gbc_btn2.fill = GridBagConstraints.BOTH;
				gbc_btn2.insets = new Insets(0, 0, 5, 5);
				gbc_btn2.gridx = 1;
				gbc_btn2.gridy = 0;
				panel.add(btn2, gbc_btn2);
			}
			{
				JButton btn3 = new JButton("3");
				btn3.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						JButton j = (JButton) e.getSource();
						if(msg.getText().equals("0")){
							msg.setText(j.getText());
						}else
							msg.setText(msg.getText()+j.getText());
					}
				});
				GridBagConstraints gbc_btn3 = new GridBagConstraints();
				gbc_btn3.fill = GridBagConstraints.BOTH;
				gbc_btn3.insets = new Insets(0, 0, 5, 5);
				gbc_btn3.gridx = 2;
				gbc_btn3.gridy = 0;
				panel.add(btn3, gbc_btn3);
			}
			{
				JButton btn4 = new JButton("4");
				btn4.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						JButton j = (JButton) e.getSource();
						if(msg.getText().equals("0")){
							msg.setText(j.getText());
						}else
							msg.setText(msg.getText()+j.getText());
					}
				});
				GridBagConstraints gbc_btn4 = new GridBagConstraints();
				gbc_btn4.fill = GridBagConstraints.BOTH;
				gbc_btn4.insets = new Insets(0, 0, 5, 5);
				gbc_btn4.gridx = 0;
				gbc_btn4.gridy = 1;
				panel.add(btn4, gbc_btn4);
			}
			{
				JButton btn5 = new JButton("5");
				btn5.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						JButton j = (JButton) e.getSource();
						if(msg.getText().equals("0")){
							msg.setText(j.getText());
						}else
							msg.setText(msg.getText()+j.getText());
					}
				});
				GridBagConstraints gbc_btn5 = new GridBagConstraints();
				gbc_btn5.fill = GridBagConstraints.BOTH;
				gbc_btn5.insets = new Insets(0, 0, 5, 5);
				gbc_btn5.gridx = 1;
				gbc_btn5.gridy = 1;
				panel.add(btn5, gbc_btn5);
			}
			{
				JButton btn6 = new JButton("6");
				btn6.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						JButton j = (JButton) e.getSource();
						if(msg.getText().equals("0")){
							msg.setText(j.getText());
						}else
							msg.setText(msg.getText()+j.getText());
					}
				});
				GridBagConstraints gbc_btn6 = new GridBagConstraints();
				gbc_btn6.fill = GridBagConstraints.BOTH;
				gbc_btn6.insets = new Insets(0, 0, 5, 5);
				gbc_btn6.gridx = 2;
				gbc_btn6.gridy = 1;
				panel.add(btn6, gbc_btn6);
			}
			{
				JButton btn7 = new JButton("7");
				btn7.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						JButton j = (JButton) e.getSource();
						if(msg.getText().equals("0")){
							msg.setText(j.getText());
						}else
							msg.setText(msg.getText()+j.getText());
					}
				});
				GridBagConstraints gbc_btn7 = new GridBagConstraints();
				gbc_btn7.fill = GridBagConstraints.BOTH;
				gbc_btn7.insets = new Insets(0, 0, 5, 5);
				gbc_btn7.gridx = 0;
				gbc_btn7.gridy = 2;
				panel.add(btn7, gbc_btn7);
			}
			{
				JButton btn8 = new JButton("8");
				btn8.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						JButton j = (JButton) e.getSource();
						if(msg.getText().equals("0")){
							msg.setText(j.getText());
						}else
							msg.setText(msg.getText()+j.getText());
					}
				});
				GridBagConstraints gbc_btn8 = new GridBagConstraints();
				gbc_btn8.fill = GridBagConstraints.BOTH;
				gbc_btn8.insets = new Insets(0, 0, 5, 5);
				gbc_btn8.gridx = 1;
				gbc_btn8.gridy = 2;
				panel.add(btn8, gbc_btn8);
			}
			{
				JButton btn9 = new JButton("9");
				btn9.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						JButton j = (JButton) e.getSource();
						if(msg.getText().equals("0")){
							msg.setText(j.getText());
						}else
							msg.setText(msg.getText()+j.getText());
					}
				});
				GridBagConstraints gbc_btn9 = new GridBagConstraints();
				gbc_btn9.fill = GridBagConstraints.BOTH;
				gbc_btn9.insets = new Insets(0, 0, 5, 5);
				gbc_btn9.gridx = 2;
				gbc_btn9.gridy = 2;
				panel.add(btn9, gbc_btn9);
			}
			{
				JButton btn0 = new JButton("0");
				btn0.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						JButton j = (JButton) e.getSource();
						if(msg.getText().equals("0")){
							msg.setText(j.getText());
						}else
							msg.setText(msg.getText()+j.getText());
					}
				});
				GridBagConstraints gbc_btn0 = new GridBagConstraints();
				gbc_btn0.fill = GridBagConstraints.BOTH;
				gbc_btn0.insets = new Insets(0, 0, 5, 5);
				gbc_btn0.gridx = 0;
				gbc_btn0.gridy = 3;
				panel.add(btn0, gbc_btn0);
			}
			{
				JButton button = new JButton("00");
				GridBagConstraints gbc_button = new GridBagConstraints();
				gbc_button.fill = GridBagConstraints.BOTH;
				gbc_button.insets = new Insets(0, 0, 5, 5);
				gbc_button.gridx = 1;
				gbc_button.gridy = 3;
				panel.add(button, gbc_button);
			}
			{
				JButton btnEnter = new JButton("ENTER");
				GridBagConstraints gbc_btnEnter = new GridBagConstraints();
				gbc_btnEnter.insets = new Insets(0, 0, 5, 5);
				gbc_btnEnter.fill = GridBagConstraints.BOTH;
				gbc_btnEnter.gridheight = 2;
				gbc_btnEnter.gridx = 2;
				gbc_btnEnter.gridy = 3;
				panel.add(btnEnter, gbc_btnEnter);
			}
			{
				JButton button = new JButton("<-");
				button.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						JButton j = (JButton)e.getSource();
						String str = msg.getText();
						if(str.length()>=1)
							msg.setText(str.substring(0, str.length()-1));
					}
				});
				GridBagConstraints gbc_button = new GridBagConstraints();
				gbc_button.fill = GridBagConstraints.BOTH;
				gbc_button.insets = new Insets(0, 0, 5, 5);
				gbc_button.gridx = 0;
				gbc_button.gridy = 4;
				panel.add(button, gbc_button);
			}
			{
				JButton btnCl = new JButton("CL");
				btnCl.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						msg.setText("0");
					}
				});
				GridBagConstraints gbc_btnCl = new GridBagConstraints();
				gbc_btnCl.insets = new Insets(0, 0, 5, 5);
				gbc_btnCl.fill = GridBagConstraints.BOTH;
				gbc_btnCl.gridx = 1;
				gbc_btnCl.gridy = 4;
				panel.add(btnCl, gbc_btnCl);
			}
		}
		{
			msg = new JTextField();
			msg.setText("0");
			msg.setHorizontalAlignment(SwingConstants.RIGHT);
			contentPanel.add(msg, BorderLayout.NORTH);
			msg.setColumns(10);
		}
	}

}
